/// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Microsoft.VSPowerToys.PackInstallerDataModel
{
	/// <summary>
	/// This class holds the data relating to a single pack.
	/// </summary>
	// This line suppresses the FxCop warning about implementing the rest of the comparison operators for this type.
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1036:OverrideMethodsOnComparableTypes")]
	public class PackItem : IComparable
	{
		private string name;

		/// <summary>
		/// The name of the pack
		/// </summary>
		public string Name
		{
			get { return this.name; }
			set { this.name = value; }
		}

		private List<ToolItem> tools = null;

		/// <summary>
		/// The list of tools associated with this pack
		/// </summary>
		// FxCop suggests that the generic List type not be used for a publicly accessible field.  In this case
		// we're specifically exploiting the sorting capabilities of the List class and there isn't really a need
		// for one of the other extensibility designed classes.
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
		public List<ToolItem> Tools
		{
			get { return this.tools; }
		}

		private Uri packUrl;

		public Uri PackUrl
		{
			get { return packUrl; }
			set { packUrl = value; }
		}


		/// <summary>
		/// Constructor, initializes an empty list of tools.
		/// </summary>
		public PackItem()
		{
			this.tools = new List<ToolItem>();
		}

        public PackItem(string packName, Uri url) : this()
        {
            this.name = packName;
            this.packUrl = url;
        }

		#region IComparable Members

		/// <summary>
		/// The CompareTo method is required to implement the IComparable interface.
		/// We want to implement this interface so we can guarantee how the packs will be sorted.
		/// In this case we want packs to sort by name.
		/// </summary>
		/// <param name="obj"></param>
		public int CompareTo(object obj)
		{
			PackItem item = obj as PackItem;
			if (item != null)
			{
				return this.name.CompareTo(item.Name);
			}

			throw new ArgumentException(Strings.PackItemCompareToInputErrorMessage);
		}

		#endregion
	}
}
